package com.tianji.learning.mq;

import com.tianji.api.dto.remark.QueueLikerDTO;
import com.tianji.common.constants.MqConstants;
import com.tianji.learning.controller.InteractionReplyController;
import com.tianji.learning.domain.po.InteractionReply;
import com.tianji.learning.service.IInteractionReplyService;
import com.tianji.learning.service.ILearningLessonService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;


/**
 * 点赞监听队列
 */
@Component
@Slf4j
@RequiredArgsConstructor
public class LikeTimesChangeListener {

    private final IInteractionReplyService service;

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = "learning.lesson.pay.queue",durable = "true"),
            exchange = @Exchange(name = MqConstants.Exchange.LIKE_RECORD_EXCHANGE,type = ExchangeTypes.TOPIC),
            key = MqConstants.Key.LIKED_TIMES_KEY_TEMPLATE

    ))
    public void remark(QueueLikerDTO dto){
        log.debug("监听点赞数为{}，更新回答的点赞数量{}",dto.getBizId(),dto.getLikedTimes());
        InteractionReply l = new InteractionReply();
        l.setId(l.getId());
        l.setLikedTimes(l.getLikedTimes());
        service.updateById(l);
    }

}
